package main

import (
	"fmt"
	"github.com/PaulXu-cn/goeval"
	"log"
)

func main() {
	defineCode := `
func AppendToFile(fileName, content string) error {
    file, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    if err!= nil {
        return err
    }
    defer file.Close()

    _, err = file.WriteString(content)
    if err!= nil {
        return err
    }
    return nil
}`

	code := `AppendToFile("hello.txt", "hello")`

	re, err := goeval.Eval(defineCode, code, "os")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(re))
}
